package com.tanhua.server.controller;

import com.tanhua.model.mongo.RecommendUser;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    //注入service
    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")//查询今日佳人
    public ResponseEntity todayBest() {
        //1.没有参数
        //2.调用service查询
        TodayBest vo = tanhuaService.todayBest();
        //3.返回结果
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/recommendation")//查询主页推荐
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {
        //1.接收参数,前端传递了两个必须的参数page和pagesize
        //2.调用service处理
        PageResult vo = tanhuaService.recommendation(page, pagesize);
        //3.返回参数,返回一个vo对象的集合
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/{userId}/personalInfo")//查询陌生人的主页（信息+动态）
    public ResponseEntity personalInfo(@PathVariable("userId")Long userId){
        //1.接收参数
        //2.调用service处理
        TodayBest vo=tanhuaService.personalInfo(userId);
        //3.返回结果
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/strangerQuestions")//查看陌生人问题
    public ResponseEntity strangerQuestions( Long userId){
        //1.接收参数
        //2.调用service处理
        String txt=tanhuaService.strangerQuestions(userId);
        //3.返回结果
        return ResponseEntity.ok(txt);
    }

    @PostMapping("/strangerQuestions")//回复陌生人问题
    public ResponseEntity strangerQuestions(@RequestBody Map map){
        //1.获取请求参数
        String id = map.get("userId").toString();
        Long userId = Long.valueOf(id);
        String reply = map.get("reply").toString();
        //2.调用service处理参数
        tanhuaService.reply(userId,reply);
        //3.返回结果
        return ResponseEntity.ok(null);
    }

    @GetMapping("/search")//搜索附近的人
    public ResponseEntity search(String gender,String distance){
        //1.接收参数
        //2.调用service层进行处理
        List<NearUserVo> vos=tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vos);
    }
}
